package com.application.screen;
/** ============================================================================= **/
import com.application.component.GetUrl;
import com.application.utils.Constant;
import com.application.utils.MethodCheck;
import com.application.utils.MethodPost;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import com.example.sispakmobile.R;
/** ============================================================================= **/

public class LoginScreen extends Activity{
	/* =========================================================================== */
	public GetUrl urlLogin;
	String SERVER_URL;
	public ProgressDialog progressDialog;
	MethodPost post						= new MethodPost();
	MethodCheck check					= new MethodCheck();
	GetUrl getUrl						= new GetUrl();
	Constant constant					= new Constant();
	Button btnLogin;
	EditText txtUsername,txtPassword;
	/* =========================================================================== */
	public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_screen);
		
        btnLogin						= (Button) findViewById(R.id.login);
        txtUsername						= (EditText) findViewById(R.id.name);
        txtPassword						= (EditText) findViewById(R.id.passwd);

    	/* ======================================================================= */
        
        btnLogin.setOnClickListener(new OnClickListener() {			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String checkLogin;
				String username			= txtUsername.getText().toString();
				String password			= txtPassword.getText().toString();
				
				checkLogin				= check.getCheck(getUrl.urlLogin, username, password, constant.getParam_login(), constant.getGet());
				String check			= checkLogin.trim();
				if(check.equals("sukses")){
					createDialog(constant.getHeader_alert()," "+ constant.getLogin_sukses() +
							constant.getSelamat_datang()+" ("+username+")");
					Intent homeScreen	= new Intent(LoginScreen.this, HomeScreen.class);

					/** 
					 * Send Parameter */
					Bundle bundle 			= new Bundle();
					bundle.putString("nama", "Randhika");

					homeScreen.putExtras(bundle);
		            startActivityForResult(homeScreen, 0);
				}
				else{
					createDialog(constant.getHeader_alert()," "+constant.getLogin_gagal());
				}
			}
		});        
	}
	/* ======================================================================= */
	private void createDialog(String title, String text) {
		AlertDialog ad = new AlertDialog.Builder(this)
				.setPositiveButton("Ok", null).setTitle(title).setMessage(text)
				.create();
		ad.show();
	}	
}
